#This is the page for topic 7k # generate the data source("../gnrnd4.R") gnrnd4(296288901,800066) # be sure that we have the right data L1 # we are looking at the frequency of each value # in the data. Find those frequencies. table(L1) # then, just because we know how to do it, # we will make a bar plot of the frequencies barplot( table(L1), main="Data from gnrnd4(296288901,800066)", xlab="Values in the data set", ylab="Frequency", ylim=c(0,20)) abline(h=0) abline(h=seq(5,20,5), lty="dotted") par(new=TRUE) barplot( table(L1), main="Data from gnrnd4(296288901,800066)", xlab="Values in the data set", ylab="Frequency", ylim=c(0,20)) # now, rather than re-enter the frequencies we # will have R compute them again and store them # in a variable we will call freqs freqs <- table(L1) # to compute the relative frequency we divide # the frequencies by the total number of items total <- length(L1) rel_freq <- freqs/total rel_freq # to compute the cumulative frequencies we # use the cumsum() function cum_count <- cumsum( freqs) cum_count # to compute the cumulative relative # frequencies we just divide the cumulative # frequencies by the total number of items cum_rel_freq <- cum_count/total cum_rel_freq # to compute the degrees to allocate in a pie # chart we just multiply the relative frequency # times 360 deg_pie <- 360*rel_freq deg_pie ############################## ## We will end up doing each of these steps for any ## similar problem. It makes more sense to capture ## all of the steps in a function and then to just ## be able to run the function when we want a ## frequency table. ############################### source("../make_freq_table.R") make_freq_table( L1 ) #### there is one more special feature that we #### should see here. We can get a nicer looking #### table by using the View() function View( make_freq_table(L1) )